﻿Imports System

Partial Public Class Master_IPORT
    Inherits System.Web.UI.MasterPage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' System.Threading.Thread.Sleep(700)
        Dim P4 As String = Request.QueryString("P4")
        If (P4 & "" = "") Then
            panelMenu.Visible = False
            panelHidePage.Visible = False
            ImgHead.ImageUrl = "../images/green/table-head1_Main.png"
            Session("HideMENU") = Nothing
        ElseIf (P4 & "" = "B") Then
            ImgHead.ImageUrl = "../images/green/table-head1.gif"
            panelMenu.Visible = True
            panelHidePage.Visible = True
        ElseIf (P4 & "" = "M") Then
            ImgHead.ImageUrl = "../images/green/table-head_Master.gif"
            panelMenu.Visible = True
            panelHidePage.Visible = True
        ElseIf (P4 & "" = "R") Then
            ImgHead.ImageUrl = "../images/green/table-head_Report.gif"
            panelMenu.Visible = True
            panelHidePage.Visible = True
        ElseIf (P4 & "" = "A") Then
            ImgHead.ImageUrl = "../images/green/table-head_Admin.gif"
            panelMenu.Visible = True
            panelHidePage.Visible = True
        ElseIf (P4 & "" = "O") Then
            ImgHead.ImageUrl = "../images/green/table-head_Operation.gif"
            panelMenu.Visible = True
            panelHidePage.Visible = True
        ElseIf (P4 & "" = "E") Then
            ImgHead.ImageUrl = "../images/green/table-head_ePayment.gif"
            panelMenu.Visible = True
            panelHidePage.Visible = True
        End If

        If (CheckSession()) Then
            If Not IsPostBack Then
                Dim ds As DataSet = Session("UserData")
                If Not (ds Is Nothing) Then
                    lbNameUser.Text = ds.Tables(0).Rows(0).Item("Name").ToString()
                    lbRoleUser.Text = ds.Tables(0).Rows(0).Item("Role_name").ToString()
                Else
                    Response.Redirect("../Form/Logon.aspx", True)
                End If
                Dim Count As Integer = 0
                Dim HTML_MENU As String = ""
                Dim drBooking As DataRow() = CType(Session("UserMenuRole"), DataSet).Tables(0).Select("Mode = 'Booking'") 'ให้ทำการ select เฉพาะ Mode Booking

                For i As Integer = 0 To drBooking.Count - 1
                    If (drBooking(i).Item("Show_Menu") & "" = "Y") Then
                        Count += 1
                        If (i = drBooking.Count - 1) Then
                            HTML_MENU &= "<li><a href='../Form/" & drBooking(i).Item("Path").ToString() & "?P1=" & drBooking(i).Item("Edit_Menu").ToString() & "&P2=" & drBooking(i).Item("Add_Menu").ToString() & "&P3=" & drBooking(i).Item("Delete_Menu").ToString() & "&P4=B'>" & drBooking(i).Item("Menu_name").ToString() & "</a></li>"
                        Else
                            HTML_MENU &= "<li class='underline'><a href='../Form/" & drBooking(i).Item("Path").ToString() & "?P1=" & drBooking(i).Item("Edit_Menu").ToString() & "&P2=" & drBooking(i).Item("Add_Menu").ToString() & "&P3=" & drBooking(i).Item("Delete_Menu").ToString() & "&P4=B'>" & drBooking(i).Item("Menu_name").ToString() & "</a></li>"
                        End If

                    End If
                Next
                LiBooking.Text = HTML_MENU
                HTML_MENU = ""
                If (Count > 0) Then
                    panelBooking.Visible = True
                Else
                    panelBooking.Visible = False
                End If
                Count = 0

                Dim drePayment As DataRow() = CType(Session("UserMenuRole"), DataSet).Tables(0).Select("Mode = 'ePayment'") 'ให้ทำการ select เฉพาะ Mode Booking

                For i As Integer = 0 To drePayment.Count - 1
                    If (drePayment(i).Item("Show_Menu") & "" = "Y") Then
                        Count += 1
                        If (i = drePayment.Count - 1) Then
                            HTML_MENU &= "<li><a href='../Form/" & drePayment(i).Item("Path").ToString() & "?P1=" & drePayment(i).Item("Edit_Menu").ToString() & "&P2=" & drePayment(i).Item("Add_Menu").ToString() & "&P3=" & drePayment(i).Item("Delete_Menu").ToString() & "&P4=E'>" & drePayment(i).Item("Menu_name").ToString() & "</a></li>"
                        Else
                            HTML_MENU &= "<li class='underline'><a href='../Form/" & drePayment(i).Item("Path").ToString() & "?P1=" & drePayment(i).Item("Edit_Menu").ToString() & "&P2=" & drePayment(i).Item("Add_Menu").ToString() & "&P3=" & drePayment(i).Item("Delete_Menu").ToString() & "&P4=E'>" & drePayment(i).Item("Menu_name").ToString() & "</a></li>"
                        End If

                    End If
                Next
                LiePayment.Text = HTML_MENU
                HTML_MENU = ""
                If (Count > 0) Then
                    panelePayment.Visible = True
                Else
                    panelePayment.Visible = False
                End If
                Count = 0

                Dim drOperation As DataRow() = CType(Session("UserMenuRole"), DataSet).Tables(0).Select("Mode = 'Operation'") 'ให้ทำการ select เฉพาะ Mode Booking

                For i As Integer = 0 To drOperation.Count - 1
                    If (drOperation(i).Item("Show_Menu") & "" = "Y") Then
                        Count += 1
                        If (i = drOperation.Count - 1) Then
                            HTML_MENU &= "<li><a href='../Form/" & drOperation(i).Item("Path").ToString() & "?P1=" & drOperation(i).Item("Edit_Menu").ToString() & "&P2=" & drOperation(i).Item("Add_Menu").ToString() & "&P3=" & drOperation(i).Item("Delete_Menu").ToString() & "&P4=O'>" & drOperation(i).Item("Menu_name").ToString() & "</a></li>"
                        Else
                            HTML_MENU &= "<li class='underline'><a href='../Form/" & drOperation(i).Item("Path").ToString() & "?P1=" & drOperation(i).Item("Edit_Menu").ToString() & "&P2=" & drOperation(i).Item("Add_Menu").ToString() & "&P3=" & drOperation(i).Item("Delete_Menu").ToString() & "&P4=O'>" & drOperation(i).Item("Menu_name").ToString() & "</a></li>"
                        End If

                    End If
                Next
                LiOperation.Text = HTML_MENU
                HTML_MENU = ""
                If (Count > 0) Then
                    panelOperation.Visible = True
                Else
                    panelOperation.Visible = False
                End If
                Count = 0

                Dim drAdmin As DataRow() = CType(Session("UserMenuRole"), DataSet).Tables(0).Select("Mode = 'Admin'") 'ให้ทำการ select เฉพาะ Mode Booking

                For i As Integer = 0 To drAdmin.Count - 1
                    If (drAdmin(i).Item("Show_Menu") & "" = "Y") Then
                        Count += 1
                        If (i = drAdmin.Count - 1) Then
                            HTML_MENU &= "<li><a href='../Master_Form/" & drAdmin(i).Item("Path").ToString() & "?P1=" & drAdmin(i).Item("Edit_Menu").ToString() & "&P2=" & drAdmin(i).Item("Add_Menu").ToString() & "&P3=" & drAdmin(i).Item("Delete_Menu").ToString() & "&P4=A'>" & drAdmin(i).Item("Menu_name").ToString() & "</a></li>"
                        Else
                            HTML_MENU &= "<li class='underline'><a href='../Master_Form/" & drAdmin(i).Item("Path").ToString() & "?P1=" & drAdmin(i).Item("Edit_Menu").ToString() & "&P2=" & drAdmin(i).Item("Add_Menu").ToString() & "&P3=" & drAdmin(i).Item("Delete_Menu").ToString() & "&P4=A'>" & drAdmin(i).Item("Menu_name").ToString() & "</a></li>"
                        End If

                    End If
                Next
                LiAdmin.Text = HTML_MENU
                HTML_MENU = ""
                If (Count > 0) Then
                    panelAdmin.Visible = True
                Else
                    panelAdmin.Visible = False
                End If
                Count = 0

                Dim drMaster As DataRow() = CType(Session("UserMenuRole"), DataSet).Tables(0).Select("Mode = 'Master'") 'ให้ทำการ select เฉพาะ Mode Master

                For i As Integer = 0 To drMaster.Count - 1
                    If (drMaster(i).Item("Show_Menu") & "" = "Y") Then
                        Count += 1
                        If (i = drBooking.Count - 1) Then
                            HTML_MENU &= "<li><a href='../Master_Form/" & drMaster(i).Item("Path").ToString() & "?P1=" & drMaster(i).Item("Edit_Menu").ToString() & "&P2=" & drMaster(i).Item("Add_Menu").ToString() & "&P3=" & drMaster(i).Item("Delete_Menu").ToString() & "&P4=M'>" & drMaster(i).Item("Menu_name").ToString() & "</a></li>"
                        Else
                            HTML_MENU &= "<li class='underline'><a href='../Master_Form/" & drMaster(i).Item("Path").ToString() & "?P1=" & drMaster(i).Item("Edit_Menu").ToString() & "&P2=" & drMaster(i).Item("Add_Menu").ToString() & "&P3=" & drMaster(i).Item("Delete_Menu").ToString() & "&P4=M'>" & drMaster(i).Item("Menu_name").ToString() & "</a></li>"
                        End If

                    End If
                Next
                LiMaster.Text = HTML_MENU
                HTML_MENU = ""
                If (Count > 0) Then
                    panelMaster.Visible = True
                Else
                    panelMaster.Visible = False
                End If
                Count = 0

                Dim drReport As DataRow() = CType(Session("UserMenuRole"), DataSet).Tables(0).Select("Mode = 'Report'") 'ให้ทำการ select เฉพาะ Mode Master

                For i As Integer = 0 To drReport.Count - 1
                    If (drReport(i).Item("Show_Menu") & "" = "Y") Then
                        Count += 1
                        If (i = drBooking.Count - 1) Then
                            HTML_MENU &= "<li><a href='../Report_Page/" & drReport(i).Item("Path").ToString() & "?P1=" & drReport(i).Item("Edit_Menu").ToString() & "&P2=" & drReport(i).Item("Add_Menu").ToString() & "&P3=" & drReport(i).Item("Delete_Menu").ToString() & "&P4=R'>" & drReport(i).Item("Menu_name").ToString() & "</a></li>"
                        Else
                            HTML_MENU &= "<li class='underline'><a href='../Report_Page/" & drReport(i).Item("Path").ToString() & "?P1=" & drReport(i).Item("Edit_Menu").ToString() & "&P2=" & drReport(i).Item("Add_Menu").ToString() & "&P3=" & drReport(i).Item("Delete_Menu").ToString() & "&P4=R'>" & drReport(i).Item("Menu_name").ToString() & "</a></li>"
                        End If

                    End If
                Next
                LiReport.Text = HTML_MENU
                If (Count > 0) Then
                    panelReport.Visible = True
                Else
                    panelReport.Visible = False
                End If


            End If
        Else
            Response.Redirect("../Form/Logon.aspx", True)
        End If

    End Sub
    Private Function CheckSession() As Boolean
        If ((Session("UserData") Is Nothing) Or (Session("Config") Is Nothing) Or (Session("UserMenuRole") Is Nothing) Or (Session("Role") Is Nothing)) Then
            Return False
        Else
            Return True
        End If
    End Function

    Private Sub imgTheme_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgTheme.Click
        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " document.getElementById('ctl00_framePopup').src = '../MasterPopup/Theme.aspx';", True)
        ModalPopupExtenderTheme.Show()
    End Sub

    Private Sub ChangeButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ChangeButton.Click
        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " document.getElementById('ctl00_framePopupChange').src = '../MasterPopup/ChangePassword.aspx';", True)
        ModalPopupExtenderChange.Show()
    End Sub
End Class